﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using FazaDemo.BL.InterfaceDomain;
using FazaDemo.ViewModels;

namespace FazaDemo.PL.Wpf
{
    class NavigatorBuilder
    {

        private readonly NavPageViewModel _navModel;

        private NavElementBuilder _elemBuilder;

        public NavigatorBuilder(NavPageViewModel navModel)
        {
            _navModel = navModel;

        }

        public void Build(TabItem tabItem, WorkArea workArea)
        {
            IList<NavElementViewModel> elemModels = _navModel.NavArea.ToList();
            var grid = new Grid();
            for (int i = 0; i < 6; i++)
            {
                grid.ColumnDefinitions.Add(new ColumnDefinition { Width = GridLength.Auto });
            }
            for (int i = 0; i < elemModels.Count + 1; i++)
            {
                grid.RowDefinitions.Add(new RowDefinition { Height = GridLength.Auto });
            }
            _elemBuilder = new NavElementBuilder(grid, workArea);
            var saveButton = new Button { Content = "Поиск" };
            grid.Children.Add(saveButton);
            Grid.SetColumn(saveButton, 0);
            Grid.SetRow(saveButton, 0);
            for (int i = 0; i < elemModels.Count; i++)
            {
                _elemBuilder.Build(elemModels[i], i + 1);
            }
            tabItem.Content = grid;
        }

    }
}
